home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15741 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.minn.net!news
  2. From: gruch@minn.net (Gerry Ruch)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Array indexing with malloc
  5. Date: Sun, 21 Apr 1996 17:03:53 GMT
  6. Organization: Minn Net
  7. Message-ID: <4ldimv$9ed@cobra.Minn.Net>
  8. References: <96110.093936F0O@psuvm.psu.edu> <4lan7j$1op@cobra.Minn.Net>
  9. NNTP-Posting-Host: dialup-217.minn.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. gruch@minn.net wrote:
  13.  
  14. >A couple of things.  
  15. >First your 64k problem.  malloc has a 64k size limit.  To allocate a
  16. >huge array you must use halloc.  The compilers I've used (i'm not
  17. >certain that this is true in all compilers) require huge arrays
  18. >allocated with halloc larger than 128k to have an elelment size that
  19. >is a power of 2.  Therefore the statement-
  20.  
  21. >ptr = halloc(1000, 3);  // 1000 elements at 3 bytes- total 3000 bytes
  22.  
  23. >is illegal.  But-
  24.  
  25. >ptr = halloc(750, 4);   // 750 elements at 4 bytes- total 3000 bytes
  26.  
  27. >is legal.  That should take care of your size limit problem.
  28.  
  29. Ok- So that was a pretty shoddy example.  3000 bytes hardly seems to
  30. add up to 128K.  Not sure what I was thinking.  A better example would
  31. have been:
  32.  
  33. Illegal:
  34. ptr = halloc(47000, 3); // 47000 elements at 3 bytes- total 141,000
  35. bytes
  36.  
  37. Legal:
  38. ptr = halloc(35250, 4); // 35250 elements at 4 bytes- total 141,000
  39. bytes
  40.  
  41. Sorry for the mistake.
  42.  
  43. ~Gerry.
  44.  
  45.